﻿using System;
using System.Collections.Generic;
using Heap; 

namespace HeapSort {
    public class HeapSort<T> {
        public static IEnumerable<T> Sort<T1>(IHeapFactory<T> factory, IEnumerable<T1> toBeOrdered, IComparer<T> comparer) where T1 : T {
            var heap = factory.CreateHeap(toBeOrdered, comparer);
            while (!heap.IsEmpty()) {
                yield return heap.ExtractMin();
            }
        }
    }

    public class HeapSortDefault<T> : HeapSort<T> where T : IComparable<T> {
        public static IEnumerable<T> Sort<T1>(IHeapFactoryDefault<T> factory, IEnumerable<T1> toBeOrdered) where T1 : T {
            var heap = factory.CreateHeap(toBeOrdered);
            while (!heap.IsEmpty()) {
                yield return heap.ExtractMin();
            }
        }
    } 
}
